from flask import Flask, request
import requests
import json

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/testpost', methods=['POST'])
def testPost():
    text = request.stream.read().decode()
    return text

@app.route('/xxx', methods=['POST'])
def xxx():
    return request.headers.get('xxx')

def start():
    app.run()

from pyocr import extractPicText

@app.route('/extractPicText', methods=['POST'])
def extractPicTextAction():
    text = request.stream.read().decode()
    jsonObj = json.loads(text)
    path = jsonObj['path']

    rs = extractPicText(path)
    return json.dumps(rs)

from gua.picsearch import findOut, findOutExact

@app.route('/picsearch', methods=['POST'])
def picsearch():
    text = request.stream.read().decode()
    jsonObj = json.loads(text)
    small = jsonObj['small']
    big = jsonObj['big']

    rs = findOut(small, big)
    
    return json.dumps(rs)

@app.route('/picsearchExact', methods=['POST'])
def picsearchExact():
    text = request.stream.read().decode()
    jsonObj = json.loads(text)
    small = jsonObj['small']
    big = jsonObj['big']

    rs = findOutExact(small, big)
    print(rs)
    return json.dumps(rs)
